import { IPSAppCounterRef } from '../../app/control/ipsapp-counter-ref';
import { PSMDAjaxControlContainerImpl } from '../psmdajax-control-container-impl';
import { IPSDETree } from './ipsdetree';
import { IPSDETreeColumn } from './ipsdetree-column';
import { IPSDETreeNode } from './ipsdetree-node';
import { IPSDETreeNodeRS } from './ipsdetree-node-rs';
import { IPSLanguageRes } from '../../res/ipslanguage-res';

export class PSDETreeImpl extends PSMDAjaxControlContainerImpl implements IPSDETree {
  get codeName(): string {
    return this.M.codeName;
  }

  get emptyText(): string {
    return this.M.emptyText;
  }

  protected emptytextpslanguageres: IPSLanguageRes | null = null;

  getEmptyTextPSLanguageRes(): IPSLanguageRes | null {
    if (this.emptytextpslanguageres != null) return this.emptytextpslanguageres;
    const value = this.M.getEmptyTextPSLanguageRes;
    if (value == null) {
      return null;
    }
    this.emptytextpslanguageres = this.getPSModel4('res.IPSLanguageRes', value, 'getEmptyTextPSLanguageRes') as IPSLanguageRes;
    return this.emptytextpslanguageres;
  }

  get emptyTextPSLanguageRes(): IPSLanguageRes | null {
    return this.getEmptyTextPSLanguageRes();
  }

  getEmptyTextPSLanguageResMust(): IPSLanguageRes {
    const value = this.getEmptyTextPSLanguageRes();
    if (value == null) {
      throw new Error('未指定无值内容语言资源');
    }
    return value;
  }

  protected psappcounterref: IPSAppCounterRef | null = null;

  getPSAppCounterRef(): IPSAppCounterRef | null {
    if (this.psappcounterref != null) return this.psappcounterref;
    const value = this.M.getPSAppCounterRef;
    if (value == null) {
      return null;
    }
    this.psappcounterref = this.findPSAppCounterRef(value);
    return this.psappcounterref;
  }

  get psAppCounterRef(): IPSAppCounterRef | null {
    return this.getPSAppCounterRef();
  }

  getPSAppCounterRefMust(): IPSAppCounterRef {
    const value = this.getPSAppCounterRef();
    if (value == null) {
      throw new Error('未指定应用计数器引用');
    }
    return value;
  }

  protected psdetreecolumns: IPSDETreeColumn[] | null = null;

  getPSDETreeColumns(): IPSDETreeColumn[] | null {
    if (this.psdetreecolumns == null) {
      this.psdetreecolumns = this.fillChildListModel(this.M.getPSDETreeColumns, 'control.tree.IPSDETreeColumn') as IPSDETreeColumn[];
    }
    return this.psdetreecolumns;
  }

  get psDETreeColumns(): IPSDETreeColumn[] | null {
    return this.getPSDETreeColumns();
  }

  findPSDETreeColumn(objKey: any): IPSDETreeColumn | null {
    return this.getPSModel5('control.tree.IPSDETreeColumn', this.getPSDETreeColumns(), objKey) as IPSDETreeColumn;
  }

  protected psdetreenoderss: IPSDETreeNodeRS[] | null = null;

  getPSDETreeNodeRSs(): IPSDETreeNodeRS[] | null {
    if (this.psdetreenoderss == null) {
      this.psdetreenoderss = this.fillChildListModel(this.M.getPSDETreeNodeRSs, 'control.tree.IPSDETreeNodeRS') as IPSDETreeNodeRS[];
    }
    return this.psdetreenoderss;
  }

  get psDETreeNodeRSs(): IPSDETreeNodeRS[] | null {
    return this.getPSDETreeNodeRSs();
  }

  findPSDETreeNodeRS(objKey: any): IPSDETreeNodeRS | null {
    return this.getPSModel5('control.tree.IPSDETreeNodeRS', this.getPSDETreeNodeRSs(), objKey) as IPSDETreeNodeRS;
  }

  protected psdetreenodes: IPSDETreeNode[] | null = null;

  getPSDETreeNodes(): IPSDETreeNode[] | null {
    if (this.psdetreenodes == null) {
      this.psdetreenodes = this.fillChildListModel(this.M.getPSDETreeNodes, 'control.tree.IPSDETreeNode') as IPSDETreeNode[];
    }
    return this.psdetreenodes;
  }

  get psDETreeNodes(): IPSDETreeNode[] | null {
    return this.getPSDETreeNodes();
  }

  findPSDETreeNode(objKey: any): IPSDETreeNode | null {
    return this.getPSModel5('control.tree.IPSDETreeNode', this.getPSDETreeNodes(), objKey) as IPSDETreeNode;
  }

  get treeGridMode(): 0 | 1 | 2 {
    return this.M.treeGridMode;
  }

  get hasWFDataItems(): boolean {
    return this.M.hasWFDataItems;
  }

  getHasWFDataItems(): boolean {
    return this.M.hasWFDataItems;
  }

  get enableEdit(): boolean {
    return this.M.enableEdit != null ? this.M.enableEdit : false;
  }

  get enableRootSelect(): boolean {
    return this.M.enableRootSelect;
  }

  get outputIconDefault(): boolean {
    return this.M.outputIconDefault;
  }

  get rootVisible(): boolean {
    return this.M.rootVisible;
  }

  get cls(): string {
    return 'PSDETreeImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.IPSControlContainer' || cls == 'control.tree.IPSDETree') return true;
    return super.instanceof(cls);
  }
}
